home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / stik_dev / extdialr.c next >
C/C++ Source or Header  |  1996-08-08  |  5KB  |  175 lines

  1.  
  2.  
  3. #include <aes.h>
  4. #include <tos.h>
  5. #include <stdio.h>
  6. #include <ctype.h>
  7. #include <string.h>
  8.  
  9. #include "transprt.h"
  10.  
  11.  
  12. #define  DIALER             'IP'
  13. #define  IP_DIAL_REQUEST    (DIALER + 0)
  14. #define  IP_DIAL_HANGUP     (DIALER + 1)
  15. #define  IP_DIAL_DONE       (DIALER + 2)
  16. #define  IP_DIAL_ERROR      (DIALER + 3)
  17.  
  18. #define  DIAL_SCRIPT        "dial.scr"
  19. #define  DIAL_MAX_NUMBER    10
  20. #define  TIMEOUT            10
  21.  
  22.  
  23. void  gem_program (void),  do_some_work (void);
  24. long  get_stik_cookie (void);
  25.  
  26. DRV_LIST   *stik_drivers;
  27. TPL        *tpl;
  28. char       alert[200];
  29. int        gl_apid;
  30.  
  31. char  not_there[] = "[1][ |  STiK is not loaded or enabled !   ][ Hmmm ]";
  32. char  corrupted[] = "[1][ |  STiK structures corrupted !   ][ Oooops ]";
  33. char  found_it[]  = "[3][ |  Driver \'%s\',|  by %s, found,   |  version %s.][ Okay ]";
  34. char  no_module[] = "[1][ |  STiK Transport Driver not found !   ][ Grmbl ]";
  35. char  no_dialer[] = "[1][ |  STiK variable DIALER not set !   ][ Grrr ]";
  36. char  not_start[] = "[1][ |  Dialer is not running !   ][ Forgot ]";
  37. char  begin_it[]  = "[3][ |  Dialer found. Sending dial request.   ][ Good ]";
  38. char  waiting[]   = "[3][ |  Waiting %d seconds for a response.   ][ Do it ]";
  39. char  dial_error_text[][70] = { "",
  40.                     "[1][ |  Dial error :| |    Script not found !   ][ Uhmmm ]",
  41.                     "[1][ |  Dial error :| |    Redials exceed max number !   ][ Uhmmm ]",
  42.                     "[1][ |  Dial error :| |    Modem reports fatal problem !   ][ Uhmmm ]",
  43.                     "[1][ |  Dial error :| |    User aborted dialing !   ][ Uhmmm ]",
  44.                     "[1][ |  Dial error :| |    Dialing already in progress !   ][ Uhmmm ]",
  45.                     "[1][ |  Dial error :| |    Already connected !   ][ Uhmmm ]"
  46.                };
  47. char  success[]   = "[3][ |  Dialing done. Connection established.   ][ Well done ]";
  48. char  other_err[] = "[1][ |  Dialer reports an error.   | |  Code unknown !][ Hey ]";
  49. char  timer_qu[]  = "[2][ |  Wait timeout expired.| |    Give it some more time ?   ][ Yes | Abort ]";
  50. char  abort_qu[]  = "[2][ |  Wanna abort waiting for response ?   ][ Yes | Continue ]";
  51.  
  52.  
  53.  
  54. void  main()
  55.  
  56. {
  57.    gl_apid = appl_init();
  58.  
  59.    gem_program();
  60.  
  61.    appl_exit();
  62.  }
  63.  
  64.  
  65. void  gem_program()
  66.  
  67. {
  68.    stik_drivers = (DRV_LIST *) Supexec (get_stik_cookie);
  69.  
  70.    if (stik_drivers == 0L) {
  71.         form_alert (1, not_there);
  72.         return;
  73.       }
  74.    if (strcmp (stik_drivers->magic, MAGIC) != 0) {
  75.         form_alert (1, corrupted);
  76.         return;
  77.       }
  78.  
  79.    tpl = (TPL *) (*stik_drivers->get_dftab) (TRANSPORT_DRIVER);
  80.  
  81.    if (tpl != (TPL *) NULL) {
  82.         sprintf (alert, found_it, tpl->module, tpl->author, tpl->version);
  83.         form_alert (1, alert);
  84.         do_some_work();
  85.       }
  86.      else
  87.         form_alert (1, no_module);
  88.  }
  89.  
  90.  
  91. long  get_stik_cookie()
  92.  
  93. {
  94.    long  *work;
  95.  
  96.    for (work = * (long **) 0x5a0L; *work != 0L; work += 2)
  97.         if (*work == 'STiK')
  98.              return (*++work);
  99.  
  100.    return (0L);
  101.  }
  102.  
  103.  
  104. void  do_some_work()
  105.  
  106. {
  107.    int   count, dialer_apid, message[8], abort, event, dummy;
  108.    long  timeout;
  109.    char  dialer_name[9], dial_script_name[] = DIAL_SCRIPT;
  110.  
  111.    strncpy (dialer_name, getvstr ("DIALER"), 9);
  112.    dialer_name[8] = '\0';
  113.  
  114.    if (strcmp (dialer_name, "0") == 0) {
  115.         form_alert (1, no_dialer);
  116.         return;
  117.       }
  118.  
  119.    for (count = (int) strlen (dialer_name); count < 8; count++)
  120.         dialer_name[count] = ' ';
  121.  
  122.    for (count = 0; count < 8; count++)
  123.         dialer_name[count] = toupper (dialer_name[count]);
  124.  
  125.    dialer_apid = appl_find (dialer_name);
  126.  
  127.    if (dialer_apid < 0) {
  128.         form_alert (1, not_start);
  129.         return;
  130.       }
  131.  
  132.    form_alert (1, begin_it);
  133.  
  134.    message[0] = IP_DIAL_REQUEST;
  135.    message[1] = gl_apid;
  136.    message[2] = 0;
  137.    *(char **) &message[3] = dial_script_name;
  138.    message[5] = DIAL_MAX_NUMBER;
  139.    for (count = 6; count < 8; count++)   message[count] = 0;
  140.  
  141.    appl_write (dialer_apid, 16, message);
  142.  
  143.    timeout = TIMEOUT * 1000L;
  144.  
  145.    sprintf (alert, waiting, (int) (timeout / 1000));
  146.    form_alert (1, alert);
  147.  
  148.    for (abort = 0; abort == 0;) {
  149.         event = evnt_multi (MU_MESAG | MU_TIMER | MU_BUTTON, 1,3,3, 0,0,0,0,0,
  150.                        0,0,0,0,0, message, (unsigned int) (timeout & 0xffff), 
  151.                        (unsigned int) (timeout >> 16), &dummy, &dummy, &dummy,
  152.                        &dummy, &dummy, &dummy);
  153.  
  154.         if (event & MU_MESAG)
  155.              switch (message[0]) {
  156.                 case IP_DIAL_DONE :
  157.                   form_alert (1, success);
  158.                   abort = 1;
  159.                   break;
  160.                 case IP_DIAL_ERROR :
  161.                   if (message[3] < 1 || 6 < message[3])
  162.                        form_alert (1, other_err);
  163.                     else
  164.                        form_alert (1, dial_error_text[message[3]]);
  165.                   abort = 1;
  166.                   break;
  167.                 }
  168.         if (event & MU_TIMER)
  169.              if (form_alert (1, timer_qu) == 2)   abort = 1;
  170.  
  171.         if (event & MU_BUTTON)
  172.              if (form_alert (1, abort_qu) == 1)   abort = 1;
  173.       }
  174.  }
  175.